package com.mac.common.util;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

public class Jasypt {

    public static void main(String[] args) {
        Jasypt.encrypt("MAC01101", "123456", "PBEWithMD5AndDES");
        //Jasypt.decrypt("MPS1", "PrM/C5Z1zqriI9yCIgKtkWhWiB+ItL9b", "PBEWithMD5AndDES");
    }

    /**
     * 解密
     * @param key
     * @param mipwd
     * @param algorithm
     */
    public static void decrypt(String key, String mipwd, String algorithm) {
        StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor();
        stringEncryptor.setPassword(key);
        stringEncryptor.setAlgorithm(algorithm);
        String result = stringEncryptor.decrypt(mipwd);
        System.out.println("==================");
        System.out.println(result);
        System.out.println("==================");
    }

    /**
     * 加密
     * @param key
     * @param pwd
     * @param algorithm
     */
    public static void encrypt(String key, String pwd, String algorithm) {
        StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor();
        stringEncryptor.setPassword(key);
        stringEncryptor.setAlgorithm(algorithm);
        String result = stringEncryptor.encrypt(pwd);
        System.out.println("==================");
        System.out.println(result);
        System.out.println("==================");
    }
}

